package com.mbigger.admin.dao;

import com.mbigger.admin.entity.RoleAcl;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface RoleAclMapper {
	
	@Insert("INSERT INTO sys_role_acl (role_id, acl_id, operator, operate_time, operate_ip) "
			+ "VALUES (#{roleId}, #{aclId}, #{operator}, #{operateTime}, #{operateIp})")
	int insert(RoleAcl roleAcl);
	
	@Delete("DELETE FROM sys_role_acl WHERE id=#{id}")
	int deleteById(@Param("id")Integer id);
	
	@Select("SELECT * FROM sys_role_acle WHERE id=#{id}")
	RoleAcl selectById(@Param("id")Integer id);
	
	@Update("UPDATE sys_role_acl SET role_id=#{roleId}, acl_id=#{aclId}, operator=#{operator}, operate_time=#{operateTime}, operate_ip=#{operateIp} "
			+ "WHERE id=#{id}")
	int updateById(RoleAcl roleAcl);
	
	@Select("<script>"
			+ "SELECT * FROM sys_role_acl WHERE role_id IN "
			+ "<foreach collection='roleIdList' item='roleId' open='(' close=')' separator=','>"
			+ "#{roleId}"
			+ "</foreach>"
			+ "</script>")
	List<Integer> getAclIdListByRoleIdList(@Param("roleIdList")List<Integer> roleIdList);
	
	@Delete("DELETE FROM sys_role_acl WHERE role_id=#{roleId}")
	void deleteByRoleId(@Param("roleId")Integer roleId);
	
	@Select("<script>"
			+ "INSERT INTO sys_role_acl (role_id, acl_id, operator, operate_time, operate_ip) "
			+ "VALUES "
			+ "<foreach collection='roleAclList' item='roleAcl' open='(' close=')' separator=','>"
			+ "(#{roleAcl.roleId}, #{roleAcl.aclId}, #{roleAcl.operator}, #{roleAcl.operateTime}, #{roleAcl.operateIp})"
			+ "</foreach>"
			+ "</script>")
	void batchInsert(@Param("roleAclList")List<RoleAcl> roleAclList);
	
	@Select("SELECT role_id FROM sys_role_acl WHERE acl_id=#{aclId}")
	List<Integer> getRoleIdListByAclId(@Param("aclId")Integer aclId);

}